﻿using System;
using System.Linq;
using System.Text;

namespace YJKRevitBase.StringUtility
{
	internal class HYBase64Coder : IStrCoder, IEnCoder
	{
		public string DeCode(string input)
		{
			input = input.Remove(0, 2);
			input = HYBase64Coder.Base64DeCodeMethod(input);
			input = new string(input.Reverse<char>().ToArray<char>());
			input = HYBase64Coder.Base64DeCodeMethod(input);
			return input;
		}

		public string EnCode(string input)
		{
			input = HYBase64Coder.Base64EnCodeMethod(input);
			input = new string(input.Reverse<char>().ToArray<char>());
			input = HYBase64Coder.Base64EnCodeMethod(input);
			input = "HY" + input;
			return input;
		}

		private static string Base64EnCodeMethod(string input)
		{
			input = Convert.ToBase64String(Encoding.UTF8.GetBytes(input));
			return input;
		}

		private static string Base64DeCodeMethod(string input)
		{
			byte[] bytes = Convert.FromBase64String(input);
			input = Encoding.UTF8.GetString(bytes);
			return input;
		}

		private const string m_useHYstr = "HY";
	}
}
